package com.oldroid.apps.getit.preferences;

import java.util.Map;

import com.oldroid.apps.getit.R;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Build;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.util.Log;

/**
 * Send Feedback Preference
 * @author Taehyun Park
 *
 */
public class EmailPreference extends Preference {
	
	Context mContext;
	String version;
	public EmailPreference(Context context) {
		super(context);
		mContext = context;
	}
	
	

	public EmailPreference(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
	}



	public EmailPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
	}



	public void setVersion(String version) {
		this.version = version;
	}

	


	@Override
	protected void onClick() {
		// TODO Auto-generated method stub
		super.onClick();
		launchEmailToIntent(mContext, version, true);
	}



	public static void launchEmailToIntent(Context context, String subject, boolean includeDebug) {
	    Intent msg = new Intent(Intent.ACTION_SEND);

	    StringBuilder body = new StringBuilder();

	    if (includeDebug) {
	      body.append(String.format("\n\n----------\nSysinfo - %s\nModel: %s\n\n",
	          Build.FINGERPRINT, Build.MODEL));


	      body.append(String.format("%s config -\n", subject));
	      

	      // Add locale info
	      body.append(String.format("locale: %s\n",
	          context.getResources().getConfiguration().locale.getDisplayName()));

	    }

	    msg.putExtra(Intent.EXTRA_EMAIL, new String[]{"MASAI LTD. <masai-google-android-camp@googlegroups.com>"});
	    msg.putExtra(Intent.EXTRA_SUBJECT, subject);
	    Log.d("EmailPreference", "Subject: "+subject);
	    msg.putExtra(Intent.EXTRA_TEXT, body.toString());

	    msg.setType("message/rfc822");
	    context.startActivity(Intent.createChooser(
	        msg, context.getString(R.string.pref_title_feedback)));
	  }
}
